package cn.nbt.busManage.model.dto;

import cn.nbt.busManage.model.entity.Bus;
import cn.nbt.busManage.model.entity.Driver;
import cn.nbt.busManage.model.entity.Route;
import cn.nbt.busManage.model.vo.BusVo;
import cn.nbt.busManage.model.vo.DriverVo;
import cn.nbt.busManage.model.vo.RouteVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * {@code @Author} lyq
 * {@code @Date} 6/11/2024 2:08 PM
 */

@Data
public class BusDto {
    private Integer id;
    private String licensePlate;
    private String model;
    private Integer capacity;
    private Integer status;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastMaintenanceDate;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime nextInspectionDate;
    private RouteDto route;
    private List<DriverDto> drivers  = new ArrayList<>();

    public BusDto(Bus bus){
        this.id = bus.getId();
        this.licensePlate = bus.getLicensePlate();
        this.model = bus.getModel();
        this.capacity = bus.getCapacity();
        this.status = bus.getStatus();
        this.lastMaintenanceDate = bus.getLastMaintenanceDate();
        this.nextInspectionDate = bus.getNextInspectionDate();
        Route busRoute = bus.getRoute();
        if (busRoute != null) {
            this.route = new RouteDto(busRoute);
        }
        List<Driver> driverList = bus.getDrivers();
        if(driverList != null) {
            List<DriverDto> driverDtoList = new ArrayList<>();
            for (Driver driver : driverList) {
                driverDtoList.add(new DriverDto(driver));
            }
            this.drivers = driverDtoList;
        }
    }

    public BusDto(BusVo busVo){
        this.id = busVo.getId();
        this.licensePlate = busVo.getLicensePlate();
        this.model = busVo.getModel();
        this.capacity = busVo.getCapacity();
        this.status = busVo.getStatus();
        this.lastMaintenanceDate = busVo.getLastMaintenanceDate();
        this.nextInspectionDate = busVo.getNextInspectionDate();
        if (busVo.getRoute() != null) {
            this.route = new RouteDto(busVo.getRoute());
        }
        List<DriverVo> driverVoList = busVo.getDrivers();
        if(driverVoList != null) {
            List<DriverDto> driverDtoList = new ArrayList<>();
            for (DriverVo driver : driverVoList) {
                driverDtoList.add(new DriverDto(driver));
            }
            this.drivers = driverDtoList;
        }
    }
}
